/*
 * Luna Driver Library. Used to access the Luna driver board via HID.
 *
 * Copyright (c) 2012 Robo Dynamics
 *
 * Author: Tyler W. Wilson
 *
 */

#ifndef __Luna_Library_h__
#define __Luna_Library_h__

#if defined(_WIN32)
	#if defined(LUNA_DLL_EXPORTS)
		#define LUNA_DLL_API __declspec(dllexport)
	#else
		#define LUNA_DLL_API __declspec(dllimport)
	#endif
#else
	#define LUNA_DLL_API
#endif /* _WIN32 */

#if defined(__cplusplus)
	extern "C" {
#endif


// Status return values: we borrow the same scheme as from libusb and HIDAPI. That is,
// any return values that are less than 0 are errors and any return values greater or
// equal to 0 menas success.


// Data structures
typedef struct _Luna_Version {
	unsigned char major;
	unsigned char minor;
} Luna_Version;

typedef struct _Luna_Sensors {
	unsigned short sonar[3];        // one for each of three sonars
	unsigned char bumper;           // only three bits. use an array of bools?
	unsigned char charger;		    // voltage
	unsigned char battery;		    // voltage
	unsigned short right_distance;	// in ticks
	unsigned short left_distance;	// in ticks
	unsigned short right_speed;		// in ticks
	unsigned short left_speed;		// in ticks
} Luna_Sensors;

typedef enum _Luna_Direction {
	DRIVE_DIRECTION_FORWARD = 0,
	DRIVE_DIRECTION_BACKWARD = 1,
	DRIVE_DIRECTION_TURN_LEFT = 2,
	DRIVE_DIRECTION_TURN_RIGHT = 3,
	DRIVE_DIRECTION_STOP = 4
} Luna_Direction;

typedef struct _Luna_Drive {
	unsigned char direction;		// Luna_Direction
	unsigned char right_speed;
	unsigned char left_speed;
} Luna_Drive;


LUNA_DLL_API int Luna_Init(void);
LUNA_DLL_API int Luna_Open(void** handle);
LUNA_DLL_API int Luna_GetVersion(void* handle, Luna_Version* version);
LUNA_DLL_API int Luna_GetSensors(void* handle, Luna_Sensors* sensors);
LUNA_DLL_API int Luna_SetDrive(void* handle, Luna_Drive* drive);
LUNA_DLL_API int Luna_Close(void* handle);
LUNA_DLL_API int Luna_Uninit(void);


#if defined(__cplusplus)
	}
#endif

#endif /* __Luna_Library_h__ */
